//
//  PictureCollectionViewCell.m
//  
//
//  Created by dlios on 15/6/3.
//
//

#import "PictureCollectionViewCell.h"

@interface PictureCollectionViewCell () <UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView *scrollview;

@end

@implementation PictureCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    self.scrollview = [[UIScrollView alloc] init];
    [self.contentView addSubview:self.scrollview];
    self.scrollview.delegate =self;
    self.scrollview.maximumZoomScale = 4.f;
    self.scrollview.minimumZoomScale = 1.f;
    
    self.imageview = [[UIImageView alloc] init];
    [self.scrollview addSubview:self.imageview];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return self.imageview;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.scrollview.zoomScale = 1;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.scrollview.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    
    self.imageview.frame = CGRectMake(0, 0, self.scrollview.bounds.size.width, self.scrollview.bounds.size.height);
    self.imageview.contentMode = UIViewContentModeScaleAspectFit;
}

@end
